package com.yupi.usercenter.stream;

import cn.hutool.core.thread.ThreadUtil;
import com.yupi.usercenter.model.dto.MonitorWoAddDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 *  推送消息
 *
 * @author wanghuizhen
 * @since Created in 2019-10-11
 */
@Component
@Slf4j
@EnableBinding(value = {OutputInterface.class})
public class MessageProducer {

    @Autowired
    private OutputInterface outputInterface;


    /**
     * 推送问题件工单数据
     * @param list 问题件工单数据
     */
    public void sendMonitorMessage(List<MonitorWoAddDTO> list){
        Message<List<MonitorWoAddDTO>> message = MessageBuilder.withPayload(list).build();
        log.info("质量工单-推送监控工单数据-重新去消费 sendMonitorMessage message:{}" ,message);
        ThreadUtil.sleep(2000);
        log.info("sendMonitorMessage 重新推送的消息,休眠2s");
        outputInterface.sendProblemWorkOrderMessage().send(message);

        // 构建消息并设置持久化模式
//        Message<List<MonitorWoAddDTO>> message = MessageBuilder
//                .withPayload(list)
//                // 设置 AMQP 消息持久化（关键）
//                .setHeader("amqp_deliveryMode", MessageDeliveryMode.PERSISTENT)
//                .build();
//        log.info("质量工单-推送监控工单数据-重新去消费 sendMonitorMessage message:{}" ,message); ThreadUtil.sleep(2000);
//        log.info("sendMonitorMessage 重新推送的消息,休眠2s");
//        // 发送消息
//        outputInterface.sendProblemWorkOrderMessage().send(message);
    }
}
